package com.opensource.lzx.restartclient.netty;

import com.opensource.lzx.restartclient.common.SpringBeanUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class NettyClient implements InitializingBean {

    @Value("${netty.server.host}")
    private String host;

    @Value("${netty.server.port}")
    private Integer port;

    @Value("${netty.server.type}")
    private String initType;

    @Override
    public void afterPropertiesSet() throws Exception {
        new Thread(() -> {
            List<INettyConnectService> connectServiceList = SpringBeanUtils.getBeanOfType(INettyConnectService.class);
            connectServiceList.stream()
                    .filter(service -> service.instanceType().getType().equals(initType))
                    .forEach(service -> service.initClient(host, port));
        }).start();
    }
}
